package com.china08.yxyapi.api.manage.edu.office.outernotice;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.office.YxyNoticeOutter;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyNoticeOutterRepository;

/**
 * 教育局行政办公 外部通知 删除通知
 * 
 */
@CrossOrigin
@RestController("OuterNoticeSendDelController")
public class OuterNoticeSendDelController extends YxyApiBaseController {

    @Autowired
    private YxyNoticeOutterRepository yxyNoticeOutterRepository;

    @RequestMapping(value = "/api_yw/manage/edu/office/outerNotice/send/del/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(//
            HttpServletRequest request, HttpServletResponse response, @PathVariable("id") String id) {
        RespModel respModel = new RespModel();
        // 当前机构
        String edbId = getProfile(request, response).getSchoolId();
        // 当前用户
        // String currentUserId = getProfile(request, response).getId();
        // 外部通知id
        List<String> idLst = Arrays.asList(id);
        // 外部通知未删除
        int deleteStatus = 0;
        List<YxyNoticeOutter> yxyNoticeOutterLst = yxyNoticeOutterRepository.findByIdInAndEdbIdAndDeleteStatus(idLst, edbId, deleteStatus);

        for (YxyNoticeOutter yxyNoticeOutter : yxyNoticeOutterLst) {
            // yxyNoticeOutter.setDeleteStatus(-1);
            yxyNoticeOutterRepository.delete(yxyNoticeOutter);
        }
        // 更改为删除状态
        // yxyNoticeOutterRepository.save(yxyNoticeOutterLst);
        respModel.setMessage("删除成功");
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {

    }
}